<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增字典')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-levelDict-add">
			<input id="treeId" name="parentId" type="hidden" th:value="${dict.dictId}"   />
			<div class="form-group">
				<label class="col-sm-3 control-label">父标签：</label>
				<div class="col-sm-8" >
				    <div class="input-group">
						<input class="form-control" type="text" th:if="${dict.dictId!=0}" onclick="selectDictTree()" id="treeName" readonly="true" th:value="${dict.parentLabel}">
						<input class="form-control" type="text" th:if="${dict.dictId==0}" readonly="true" th:value="${dict.parentLabel}">
					    <span class="input-group-addon" ><i class="fa fa-search" th:if="${dict.dictId!=0}"></i></span>
				    </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">字典标签：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="dictLabel" id="dictLabel" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">显示排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="orderNum" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">字典值：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="dictValue">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">字典状态：</label>
				<div class="col-sm-8">
				    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/levelDict";
		
		$("#form-levelDict-add").validate({
			onkeyup: false,
			rules:{
				deptName:{
					remote: {
		                url: prefix + "/checkDictLabelUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"parentId": function() {
		                		return $("input[name='parentId']").val();
		                    },
		                	"dictLabel" : function() {
		                        return $.common.trim($("#dictLabel").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				orderNum:{
					digits:true
				},
				email:{
                    email:true,
        		},
        		phone:{
        			isPhone:true,
        		},
			},
			messages: {
		        "dictLabel": {
		            remote: "字典键已经存在"
		        }
		    },
		    focusCleanup: true
		});
        var submitFlag = false;
		function submitHandler() {
	        if ($.validate.form()) {
                if(submitFlag){
                    return;
                }
                submitFlag = true;
	        	$.operate.save(prefix + "/add", $('#form-levelDict-add').serialize());
	        }
	    }
	
		/*部门管理-新增-选择父部门树*/
		function selectDictTree() {
			var options = {
				title: '字典选择',
				width: "380",
				url: prefix + "/selectDictTree/" + $("#treeId").val(),
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var body = layer.getChildFrame('body', index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			layer.close(index);
		}
	</script>
</body>
</html>
